# Contributor: Laurent Bercot <ska-devel@skarnet.org>
# Maintainer: Laurent Bercot <ska-devel@skarnet.org>
pkgname=utmps
# NOTE: If you're upgrading to a new version that fixes some security
# vulnerability, rebuild the following aports:
# - busybox
# - dropbear
# - mingetty
# - openssh
# - util-linux
pkgver=0.1.2.2
pkgrel=0
pkgdesc="A secure utmp/wtmp implementation"
url=https://skarnet.org/software/utmps/
arch="all"
options="!check"  # No test suite
license="ISC"
depends="s6-ipcserver>=2.12"
depends_static="skalibs-static"
makedepends="skalibs-dev>=2.14"
subpackages="$pkgname-static $pkgname-libs $pkgname-dev $pkgname-doc $pkgname-openrc"
source="https://skarnet.org/software/utmps/utmps-$pkgver.tar.gz
	utmp-prepare.initd
	utmpd.initd
	wtmpd.initd
	btmpd.initd
	utmp-init.initd
	setup-utmp
	utmps.pc
	wtmpd.logrotate
	btmpd.logrotate
	0001-add-stub-utmp.h.patch"
install="utmps.pre-install"

prepare() {
	default_prepare
	sed -i -e "s/@@VERSION@@/$pkgver/g" -- "$srcdir"/*.pc
}

build() {
	./configure \
		--enable-shared \
		--enable-static \
		--disable-allstatic \
		--libdir=/usr/lib \
		--libexecdir="/lib/$pkgname" \
		--with-lib=/usr/lib \
		--with-dynlib=/lib
	make
}

package() {
	make DESTDIR="$pkgdir" install

	install -D -m755 "$srcdir/utmp-prepare.initd" "$pkgdir/etc/init.d/utmp-prepare"
	install -D -m755 "$srcdir/utmpd.initd" "$pkgdir/etc/init.d/utmpd"
	install -D -m755 "$srcdir/wtmpd.initd" "$pkgdir/etc/init.d/wtmpd"
	install -D -m755 "$srcdir/btmpd.initd" "$pkgdir/etc/init.d/btmpd"
	install -D -m755 "$srcdir/utmp-init.initd" "$pkgdir/etc/init.d/utmp-init"
	install -D -m644 "$srcdir/wtmpd.logrotate" "$pkgdir/etc/logrotate.d/wtmpd"
	install -D -m644 "$srcdir/btmpd.logrotate" "$pkgdir/etc/logrotate.d/btmpd"
	install -D -m755 "$srcdir/setup-utmp" "$pkgdir/sbin/setup-utmp"
	install -D -m644 "$srcdir/utmps.pc" "$pkgdir/usr/lib/pkgconfig/utmps.pc"

	mkdir -p "$pkgdir/usr/share/doc"
	cp -a "$builddir/doc" "$pkgdir/usr/share/doc/$pkgname"
}

sha512sums="
57a73658ecb947af9dfad7a5e2931660ad1b8fa61d36c803c373e8aba13e9afa8398c1522765f5ea2b5df87d942cea17062faf30f589afa6acc744ff3ae4a409  utmps-0.1.2.2.tar.gz
05d730a7ac770e91617a9db2b250c818f7733a3cbba3e539dbea23efeea71f65b059ec7778648bbedc2a6ac3b7907ac49d786cdadcfb716b29d8e9ce514d0f3a  utmp-prepare.initd
c939657b36512ab092c51d45978fda6bb8d206f7295f733ef05c1bbce5ae68ea9bd3979e6c99bf8bf569363764467b85d68d61968a11903395c9561c6c82d59c  utmpd.initd
248c60c4f769a311f8167a38473e0de34aa2f73286552bc9344ba46558badcaa0f7d2fee282f31a031df242e474bef1e86e6527a7fd190d76600136bee851182  wtmpd.initd
c1bd4cc6b0ca88e59b6de4ba79e1a108ac717e88b3e7036e04abbeab6ec9593c63006fad8c0e7149d652928a9473fdc2b8417940a6db95f3b6c7070c272eb3db  btmpd.initd
d817c43b47893777b88f8e7c20fa6294a096cfa060f22f6355add4202c86c420fe2a8be83982786c05410add5268e5d8e558105ef4105f40b83e0ce00dcc46f1  utmp-init.initd
b6249ae817641b93aaa37842efe4fe6f9055f1fe4581edbc94f037e5d63b01ebd31136fb3cbf563c887ecd8f4764a5a92d351ca6f63e24e8e6bb423a2d5196ff  setup-utmp
15347bd95f7e69409fb5849eeca0632d3e7cdd0ad6113ab89d9f6554ebce01996522783f3f4a29877fd0f74607a5367af8483396f70d075315c4f17acc182f5e  utmps.pc
5ade986bbed30ea82b8806a3d7a0ab09a7203fb8e4c9b8785e2d549973b33644a51c522cc8891a09d5016d4b47bf848224d10d0b9834a4c77929e68c7b95d293  wtmpd.logrotate
e085ca6d4ad3817dccb7de7f7feafad586ef567b7f81fcb7ffaf1cec75a0bc18a2023cfe0761f125d4a21975e4754d235e9bd54ed2246f9c1f17607fc0cb00de  btmpd.logrotate
0512f0daa216919a886e6a8e5a73db1d29acd66d929f38d5df40bd55f0d446402610c59da12688b75c3c1230af9b1929793ed8bfc9b4593851bf496fc0a8d835  0001-add-stub-utmp.h.patch
"
